Skip to content

feat: BitVec.eq_of_getElem_eq#5213

Closed
tobiasgrosser wants to merge 5 commits intoleanprover:masterfrom
opencompl:eq_of_getElem_eq
Closed

feat: BitVec.eq_of_getElem_eq#5213
tobiasgrosser wants to merge 5 commits intoleanprover:masterfrom
opencompl:eq_of_getElem_eq

Conversation

@tobiasgrosser
Copy link
Contributor

No description provided.

@tobiasgrosser tobiasgrosser requested a review from kim-em as a code owner August 30, 2024 05:52
@github-actions github-actions bot added the toolchain-available A toolchain is available for this PR, at leanprover/lean4-pr-releases:pr-release-NNNN label Aug 30, 2024
@ghost
Copy link

ghost commented Aug 30, 2024

Mathlib CI status (docs):

  • ❗ Batteries/Mathlib CI will not be attempted unless your PR branches off the nightly-with-mathlib branch. Try git rebase a47c590a914e5ed564d07e8ec303c77b81f51c5c --onto 9ce15fb0c61e3a1bee17fd81647ed4d02b4f6c6d. (2024-08-30 06:10:07)

omega

theorem eq_of_getElem_eq {x y : BitVec w}
(pred : ∀ (i : Fin w), x[i] = y[i]) : x = y := by
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the preferred spelling of this would be to use Nat instead of Fin to be consistent with the bits of the API added in #5200.

Suggested change
(pred : ∀ (i : Fin w), x[i] = y[i]) : x = y := by
(pred : ∀ (i : Nat) (_ : i < w), x[i] = y[i]) : x = y := by

See also the analogous lemma List.ext_getElem.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems for BitVec we used historically:

theorem eq_of_getLsbD_eq {x y : BitVec w}
    (pred : ∀(i : Fin w), x.getLsbD i.val = y.getLsbD i.val) : x = y := by

theorem eq_of_getMsbD_eq {x y : BitVec w}
    (pred : ∀(i : Fin w), x.getMsbD i.val = y.getMsbD i.val) : x = y := by

I guess we should at the very least remain consistent within BitVec.

I now added both variants to this PR and ported one theorem to show the code impact. Happy to flip to Nat, but would appreciate a comment why this is preferable over Fin.

@tobiasgrosser tobiasgrosser marked this pull request as draft August 31, 2024 13:39
@kim-em
Copy link
Collaborator

kim-em commented Sep 4, 2024

I don't think it's a good idea to prove theorems about zeroExtend without having proved the corresponding theorems about zeroExtend' first.

Comment on lines +173 to +174
theorem getElem_eq_toNat_testBit (x : BitVec w) (i : Fin w) :
x[i] = x.toNat.testBit i := rfl
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should use separate i : Nat and h : i < w arguments, otherwise it's only applicable for getElem of the coercion of a Fin.

@kim-em
Copy link
Collaborator

kim-em commented Sep 4, 2024

@tobiasgrosser, e.g. my first steps here would be #5247.

@tobiasgrosser
Copy link
Contributor Author

This was resolved in #5247.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

toolchain-available A toolchain is available for this PR, at leanprover/lean4-pr-releases:pr-release-NNNN

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants